package com.shuqi.model.parse.parser;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.model.bean.PayItemInfo;
import com.shuqi.model.bean.PayTypeAllInfo;
import com.shuqi.model.bean.PayTypeInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 充值明细解析器
 * 
 * @author chenwei
 * 
 */
public class PayTypeParser extends HandlerBase {
    private PayTypeAllInfo payTypeAllInfo;

    private PayTypeInfo payTypeInfo;

    private PayItemInfo payItemInfo;

    private String code;

    private String msg;

    @Override
    public Object getParsedData() {
        return payTypeAllInfo;
    }

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        payTypeAllInfo = new PayTypeAllInfo();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {

        if (localName.equals("Recharge")) {
            payTypeAllInfo.setCode(isNull(attributes, "code"));
            payTypeAllInfo.setMsg(isNull(attributes, "msg"));
        } else if (localName.equals("Item")) {
            payItemInfo = new PayItemInfo();
            payItemInfo.setItemId(isNull(attributes, "itemId"));
            payItemInfo.setPrice(isNull(attributes, "price"));
            payItemInfo.setPpDou(isNull(attributes, "ppDou"));
            payItemInfo.setPpDouName(isNull(attributes, "ppDouName"));
            payItemInfo.setPrivilege(isNull(attributes, "privilege"));
            payTypeInfo.getPayItemInfos().add(payItemInfo);
        } else if (localName.equals("Type")) {
            payTypeInfo = new PayTypeInfo();
            payTypeInfo.setTypeId(isNull(attributes, "typeId"));
            payTypeInfo.setCardName(isNull(attributes, "cardName"));
            payTypeAllInfo.getPayTypeInfos().add(payTypeInfo);
        } else if (localName.equals("Hint")) {
            String hint = isNull(attributes, "info");
            payTypeInfo.getHintsList().add(hint);
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        super.characters(ch, start, length);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        super.endElement(uri, localName, qName);
    }

    @Override
    public void endDocument() throws SAXException {
        // TODO Auto-generated method stub
        super.endDocument();
    }
}
